package com.ccs.demo.mapper;


import com.ccs.demo.model.UserInfo;
import org.apache.catalina.User;
import org.apache.ibatis.annotations.*;

import javax.naming.InsufficientResourcesException;
import java.util.List;



@Mapper //与数据库的数据建立映射关系
public interface UserInfoMapper {

    //查找命令
    @Select("select * from user_info")
    //调用UserInfo类的List
    List<UserInfo> selectAll();

//    @Select("select * from user_info where id=#{id}")
//    UserInfo selectById(Integer id);
//
//    @Select("select * from user_info where name=#{name}")
//    UserInfo selectByName(String name);
//
//    @Select("select * from user_info where id=#{id}")
//    UserInfo selectById2(Integer Id);
//
//    @Select("select * from user_info where name=#{name}")
//    UserInfo selectByName2(String name);
//
//    @Select("select * from user_info where deleteFlag=#{deleteFlag} and age=#{age}")
//    List<UserInfo> selectByName(Integer deleteFlag,Integer age);
//
//    @Insert("insert into user_info(username,password,age) values (#{username},#{password}#{age})")
//    Integer insertUser(UserInfo userInfo);

    @Select ("select * from user_info where id=#{id}")
    UserInfo selectById(Integer id);

    @Select ("select * from user_info where username=#{username}")
    List<UserInfo> selectByName(String username);

    @Select ("select * from user_info where id=#{id}")
    List<UserInfo> selectById2(Integer id);

    @Select ("select * from user_info where username=#{username}")
    List<UserInfo> selectByName2(String username );


//    @Select("select * from user_info where age=#{age} and delete_Flag=#{deleteFlag}")
//    List<UserInfo> selectByAge(Integer age,Integer deleteFlag);

    //插入数据 返回改变的的条数

    @Insert("insert into user_info (username,password,age) values (#{username},#{password},#{age})")
    Integer insertUser(UserInfo userInfo);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user_info (username,password,age) values (#{username},#{password},#{age})")
    Integer insertUser2(UserInfo userInfo);

    @Delete("delete from user_info where id=#{id}")
    Integer deleteById(Integer id);

    @Update("update user_info set password=#{password} where id=#{id}")
    Integer updateById(UserInfo userInfo);

    @Select("select * from user_info order by id ${order}")
    List<UserInfo> selectByOrder(String order);

    @Select("select id, username, `password`, age, gender, phone, delete_flag, " +
            "create_time, update_time from user_info")
    public List<UserInfo> queryAllUser();

    @Select("select * from user_info where age=#{age}")
    List<UserInfo> selectByAge(Integer age);


}

